package engineer.automatapp.servlets;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.xml.namespace.QName;

import org.apache.axis.client.Call;
import org.apache.axis.client.Service;

/**
 * Servlet implementation class SendToBuyServlet
 */
@WebServlet("/SendToBuyServlet")
public class SendToBuyServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		response.setCharacterEncoding("UTF-8"); 
		  PrintWriter out = response.getWriter();
		try{
			  
			
			   String id=request.getParameter("machineID");
			   int machineID=Integer.parseInt(id);
			   String id2 = request.getParameter("trademarkID");
			   int trademarkID = Integer.parseInt(id2);
	           String endpoint = "http://localhost:8080/Server/services/Automat";
	           Service service = new Service();
	           Call call = (Call) service.createCall();
	           call.setTargetEndpointAddress( new java.net.URL(endpoint) );
	           call.setOperationName( new QName("http://util.com.pl", "buyTrademark") );
	           String ret = (String) call.invoke( new Object[] {machineID, trademarkID} );
	           out.println(ret);
	           }
	           catch(Exception e){
	               System.err.println(e.toString());
	           }
	}


}
